// 设备config文件
export const applyBloodDevice = ['HA08A', 'HA08B', 'HA08C', 'HA08Z', 'HA08ZW', 'HA03Y', 'HA03YD', 'HA03G', 'HA03X',]; // 支持血压功能与血压数据查看的设备
export const noApplyHeartDevice = ['HA08A', 'HA08B', 'HA08C', 'HA08Z', 'HA08ZW', 'HA03Y', 'HA03G', 'HA03F', 'HA03E', 'HA02Z', "HA03C"]; // 不支持脉率数据查看的设备
export const applySettingArray = ['HA05XJ', 'HA01YY', 'HA01YD', 'HA01CD', 'HA01CX', "HA01CZ", 'HA06T', 'HA06P', 'HA06Y', 'HA05P', 'HA05X', 'HA05E', 'HA05T', 'HA08A', 'HA08B', 'HA08C', "HA08Z", 'HA08T', 'HA08ZW', 'HA03Y', 'HA03G', 'HA03W', 'HA03X', 'HA03T', 'HA03T', 'HA03B', 'HA03C'] // 支持设备设置
export const clockArray = ['HA03Y', 'HA03YD', 'HA03TD', 'HA03W', 'HA03G', 'HA03Z', 'HA03B', "HA03C", "HA03T", 'HA01YY', 'HA01YD', 'HA01YS']; //闹钟
export const uploadArray = ['HA03Y', 'HA03YD',]; // 上传数据设置
export const HA01ImageArray = ['HA01Y', 'HA01YT', 'HA01CW', 'HA01CD', 'HA01YZ', 'HA01YW']; // HA01系列图片判断
export const HA05HeartIcons = ['HA06X', 'HA05X', 'HA05P', 'HA05E', 'HA05AW']; // 设置05系列心率测量主题
export const applyThemeArray = ['HA08A', 'HA08B', 'HA08C', "HA08Z", 'HA08ZW', 'HA08T', "HA03B", "HA03G", "HA03W", "HA03C"]; //支持主题切换
export const screenLightArray = ['HA05E', 'HA05T', 'HA05X', 'HA05XJ', 'HA05P', 'HA06Y', 'HA06P', 'HA06T', 'HA01CZ', 'HA01CX',] // 支持抬手亮屏
export const wifiArray = ['YY01', 'HA03Y', 'HA03YD']; // 配网的手表一键呼远程
export const noApplyZFB = ['HA08A', 'HA08B', 'HA08C', 'HA08Z', 'HA08ZW', 'HA05P', 'HA06Y', "HA06X", "HA06P"] // 有这些型号就不显示租赁
export const pointerMethod1 = ["HA05P", "HA05X", "HA05XJ", "HA06Y", "HA06P", 'HA06X', 'HA06T'] // 指针方式一
export const pointerMethod2 = ["HA05T"] // 手动补偿数据
export const handshakeDevices = ["HA02Z", "HA03Z"]// 握手协议
export const applyAcupoints = ["HA01YY", 'HA01YD']// 支持五穴同频设备
export const applySleepDevices = ['HA01YY', "HA01YS", 'HA01YD', "HA01YSD"] // 睡眠模式
export const offlineCourseDevices = ['HA03T', "HA03YD"] // 支持离线疗程
export const wifiDevices = ['HA03Y', 'HA03YD', 'YY01', 'YY08']; // wifi设备
export const yjhDevices = ['YY01', 'YY08']; // yy01设备


// HA08/C主题设置
export const themeHA08AC = [
    {
        id: 1,
        title: '主题1',
        img: 'https://bjy-dev.oss-cn-shenzhen.aliyuncs.com/xcx/blood/theme1.png',
    },
    {
        id: 2,
        title: '主题2',
        img: 'https://bjy-dev.oss-cn-shenzhen.aliyuncs.com/xcx/blood/theme2.png',
    },
    {
        id: 3,
        title: '主题3',
        img: 'https://bjy-dev.oss-cn-shenzhen.aliyuncs.com/xcx/blood/theme3.png',
    },
    {
        id: 4,
        title: '主题4',
        img: 'https://bjy-dev.oss-cn-shenzhen.aliyuncs.com/xcx/blood/Dialtheme2.png',
    },
    {
        id: 5,
        title: '主题5',
        img: 'https://bjy-dev.oss-cn-shenzhen.aliyuncs.com/xcx/blood/Dialtheme.png',
    },
];


// HA0B主题设置
export const themeHA08B = [
    {
        id: 1,
        title: '主题1',
        img: 'https://bjy-dev.oss-cn-shenzhen.aliyuncs.com/xcx/blood/theme1.png',
    },
    {
        id: 2,
        title: '主题2',
        img: 'https://bjy.oss-cn-shenzhen.aliyuncs.com/xcx/images/theme1.jpg',
    },
    {
        id: 3,
        title: '主题3',
        img: 'https://bjy.oss-cn-shenzhen.aliyuncs.com/xcx/images/theme2.jpg',
    },
];

// HA08Z、HA08T、HA08ZW主题设置
export const themeHA08 = [
    {
        id: 1,
        title: '主题1',
        img: 'https://bjy-dev.oss-cn-shenzhen.aliyuncs.com/xcx/blood/theme1.png'
    },
    {
        id: 2,
        title: '主题2',
        img: 'https://bjy.oss-cn-shenzhen.aliyuncs.com/xcx/images/theme1.jpg'
    },
    {
        id: 3,
        title: '主题3',
        img: 'https://bjy.oss-cn-shenzhen.aliyuncs.com/xcx/images/theme2.jpg'
    },
    {
        id: 4,
        title: '主题4',
        img: 'https://bjy-crmeb.oss-cn-shenzhen.aliyuncs.com/attach/2024/06/538be2024060718083241.jpg'
    },
];

// HA03系列
export const themeHA03 = [
    {
        id: 1,
        title: '主题1',
        img: 'https://bjy.oss-cn-shenzhen.aliyuncs.com/xcx/images/20220726/7e519178162170569540275acedeefb4.png'
    },
    {
        id: 2,
        title: '主题2',
        img: 'https://bjy.oss-cn-shenzhen.aliyuncs.com/xcx/images/20220726/1c547fc810d504b5702a1f9136659a8f.png'
    },
    {
        id: 3,
        title: '主题3',
        img: 'https://bjy.oss-cn-shenzhen.aliyuncs.com/xcx/images/20220726/6e903d124e375eb03314a3128233ac45.png'
    },
];

/* 
 设置不同手表手环对应的不同低电阀值的激光模式(laser)，计时模式(timing)参数 
*/
export const batteryArray = [
    {
        id: 1,
        devcie: ['HA01CZ', 'HA06T', 'HA06X', 'HA06Y', 'HA06P', 'HA01CD'],
        list: {
            laser: {
                params_one: 3720,
                params_two: 3670,
            },
            timing: {
                params_one: 3730,
                params_two: 3670,
            },
        },
    },
    {
        id: 2,
        devcie: ['HA01D', 'HA01T', 'HA01Y', 'HA01YT', 'HA01YZ', 'HA01YW'],
        list: {
            laser: {
                params_one: 3720,
                params_two: 3680,
            },
            timing: {
                params_one: 3730,
                params_two: 3680,
            },
        },
    },
    {
        id: 3,
        devcie: ['HA02ZY', 'HA03ZR', 'HA05A', 'HA05T', 'HA05X', 'HA08A', 'HA05P', 'HA05E'],
        list: {
            laser: {
                params_one: 3710,
                params_two: 3650,
            },
            timing: {
                params_one: 3720,
                params_two: 3650,
            },
        },
    },
    {
        id: 4,
        devcie: ['HA03Y', 'HA03W', 'HA03G', 'HA03B', 'HA03X', 'HA03T', "HA03C", 'HA03TD'],
        list: {
            laser: {
                params_one: 3690,
                params_two: 3650,
            },
            timing: {
                params_one: 3700,
                params_two: 3650,
            },
        },
    },
    {
        id: 5,
        devcie: ['HA08B', 'HA08C', 'HA08Z', 'HA08ZW', 'HA08T'],
        list: {
            laser: {
                params_one: 3640,
                params_two: 3580,
            },
            timing: {
                params_one: 3650,
                params_two: 3580,
            },
        },
    },
];

// 查询对应有激光协议的固件版本
const laserByHeartVersions = [{
    device_code: "HA01T",
    newVersion: '',
    version: '2.0.38'
},
{
    device_code: "HA01D",
    newVersion: '',
    version: '2.0.38'
},
{
    device_code: "HA01Y",
    newVersion: '',
    version: '2.0.38'
},
{
    device_code: "HA01YT",
    newVersion: '2.0.0.4',
    version: '2.0.74'
},
{
    device_code: "HA01YZ",
    newVersion: '2.0.0.4',
    version: '2.0.74'
},
{
    device_code: "HA01CT",
    newVersion: '2.0.0.4',
    version: '2.0.74'
},
{
    device_code: "HA01CX",
    newVersion: '2.0.0.4',
    version: '2.0.74'
},
{
    device_code: "HA05T",
    newVersion: '2.0.0.4',
    version: '2.0.74'
},
{
    device_code: "HA05X",
    newVersion: '2.0.0.4',
    version: '2.0.74'
},
{
    device_code: "HA05XJ",
    newVersion: '',
    version: '2.0.36'
},
{
    device_code: "HA05PZ",
    newVersion: '2.0.0.5',
    version: '2.0.75'
},
{
    device_code: "HA05P",
    newVersion: '2.0.0.5',
    version: '2.0.75'
}, {
    device_code: "HA06T",
    newVersion: '2.0.0.4',
    version: '2.0.74'
}, {
    device_code: "HA06Y",
    newVersion: '2.0.0.4',
    version: '2.0.74'
},
{
    device_code: "HA06P",
    newVersion: '2.0.0.5',
    version: '2.0.75'
},
{
    device_code: "HA08A",
    newVersion: '5.0.0.5',
    version: '5.1.75'
},
{
    device_code: "HA08B",
    newVersion: '5.0.0.5',
    version: '5.1.75'
},
{
    device_code: "HA08C",
    newVersion: '5.0.0.5',
    version: '5.1.75'
},
{
    device_code: "HA08T",
    newVersion: '5.0.0.5',
    version: '5.1.75'
}, {
    device_code: "HA08Z",
    newVersion: '5.0.0.5',
    version: '5.1.75'
},
{
    device_code: "HA08ZW",
    newVersion: '5.0.0.5',
    version: '5.1.75'
},
{
    device_code: "HA01CZ",
    newVersion: '2.0.0.3',
    version: '3.1.73'
},
{
    device_code: "HA02Z",
    newVersion: '',
    version: '3.1.65'
},
{
    device_code: "HA03Z",
    newVersion: '',
    version: '3.1.65'
},
{
    device_code: "HA03W",
    newVersion: '',
    version: '3.1.70'
},
{
    device_code: "HA03B",
    newVersion: '',
    version: '3.1.71'
},
{
    device_code: "HA03G",
    newVersion: '3.0.0.3',
    version: '3.1.73'
},
{
    device_code: "HA01YY",
    newVersion: '2.0.0.4',
    version: '2.1.74'
},
{
    device_code: "HA01YD",
    newVersion: '2.0.0.4',
    version: '2.1.74'
},
{
    device_code: "HA03C",
    newVersion: '3.0.0.3',
    version: '3.1.73'
},
{
    device_code: "HA03T",
    newVersion: '3.0.0.3',
    version: '3.1.73'
},
{
    device_code: "HA03X",
    newVersion: '3.0.0.3',
    version: '3.1.73'
}, {
    device_code: "HA03Y",
    newVersion: '3.0.0.3',
    version: '3.1.73'
},
{
    device_code: "HA03TD",
    newVersion: '3.0.0.3',
    version: '3.1.73'
}
]


function compareVersion(v1, v2) {
    const parts1 = v1.split('.').map(Number);
    const parts2 = v2.split('.').map(Number);
    const len = Math.max(parts1.length, parts2.length);
    for (let i = 0; i < len; i++) {
        const num1 = parts1[i] || 0;
        const num2 = parts2[i] || 0;
        if (num1 > num2) return 1;
        if (num1 < num2) return -1;
    }
    return 0;
}

export function checkDeviceVersion(device_code, reportedVersion) {
    const item = laserByHeartVersions.find(d => d.device_code == device_code);
    if (!item) {
        return {
            matched: false,
            message: `设备 ${device_code} 未找到`,
        };
    }

    const dotCount = (reportedVersion.match(/\./g) || []).length;
    const compareTo = dotCount === 3 ? 'newVersion' : 'version';
    const targetVersion = item[compareTo];
    if (!targetVersion) {
        return {
            matched: false,
            message: `未找到用于比较的 ${compareTo}`,
        };
    }
    const result = compareVersion(reportedVersion, targetVersion);
    return {
        matched: true,
        device_code,
        reportedVersion,
        compareTo,
        targetVersion,
        result,
        status: result === -1 ? '需要更新' : result === 0 ? '版本一致' : '当前版本高于配置',
    };
}


// 根据SN编号匹配对应的device_code
export const modelDevices = [{
    device_code: 'HA01CZ',
    isChina: true,
    movement: "AQ",
}, {
    device_code: 'HA01CZ',
    isChina: true,
    movement: "BQ",
}, {
    device_code: 'HA02Z',
    isChina: true,
    movement: "BT"
}, {
    device_code: 'HA02Z',
    isChina: true,
    movement: "AT"
}, {
    device_code: 'HA03Z',
    isChina: true,
    movement: "AV"
}, {
    device_code: 'HA03Z',
    isChina: true,
    movement: "BV"
}, {
    device_code: 'HA03W',
    isChina: true,
    movement: "CF"
}, {
    device_code: 'HA03B',
    isChina: true,
    movement: "CR"
}, {
    device_code: 'HA03G',
    isChina: true,
    movement: "CG"
},
{
    device_code: 'HA01YD',
    isChina: true,
    movement: "DE"
},
{
    device_code: 'HA01YY',
    isChina: true,
    movement: "DE"
}, {
    device_code: 'HA03C',
    isChina: true,
    movement: "DD"
}, {
    device_code: 'HA03T',
    isChina: true,
    movement: "DB"
}, {
    device_code: 'HA03X',
    isChina: true,
    movement: "CQ"
}, {
    device_code: 'HA03Y',
    isChina: true,
    movement: "CE"
},
{
    device_code: 'HA03TD',
    isChina: true,
    movement: "CE"
},
{
    device_code: 'BJ04',
    isChina: true,
    movement: "ZA"
},
{
    device_code: 'HA01T',
    isChina: false,
    movement: "CD"
},
{
    device_code: 'HA01YT',
    isChina: false,
    movement: "BL"
},
{
    device_code: 'HA01YT',
    isChina: false,
    movement: "AL"
},
{
    device_code: 'HA01YZ',
    isChina: false,
    movement: "CY"
},
{
    device_code: 'HA01CT',
    isChina: false,
    movement: "CC"
},
{
    device_code: 'HA01CX',
    isChina: false,
    movement: "AJ"
},
{
    device_code: 'HA01CX',
    isChina: false,
    movement: "BJ"
},
{
    device_code: 'HA05T',
    isChina: false,
    movement: "AU"
},
{
    device_code: 'HA05T',
    isChina: false,
    movement: "BU"
},
{
    device_code: 'HA05X',
    isChina: false,
    movement: "AM"
},
{
    device_code: 'HA05X',
    isChina: false,
    movement: "BM"
},
{
    device_code: 'HA05XJ',
    isChina: false,
    movement: "AH"
},
{
    device_code: 'HA05XJ',
    isChina: false,
    movement: "BH"
},
{
    device_code: 'HA05P',
    isChina: false,
    movement: "CT"
},
{
    device_code: 'HA06T',
    isChina: false,
    movement: "AY"
},
{
    device_code: 'HA06T',
    isChina: false,
    movement: "BY"
},
{
    device_code: 'HA06Y',
    isChina: false,
    movement: "AN"
},
{
    device_code: 'HA06Y',
    isChina: false,
    movement: "BN"
},
{
    device_code: 'HA06P',
    isChina: false,
    movement: "CS"
},
{
    device_code: 'HA08A',
    isChina: false,
    movement: "AS"
},
{
    device_code: 'HA08A',
    isChina: false,
    movement: "BS"
},
{
    device_code: 'HA08B',
    isChina: false,
    movement: "CN"
},
{
    device_code: 'HA08Z',
    isChina: false,
    movement: "CX"
},
{
    device_code: 'HA08C',
    isChina: false,
    movement: "CP"
},
{
    device_code: 'HA08T',
    isChina: false,
    movement: "DC"
},
{
    device_code: 'HA08ZW',
    isChina: false,
    movement: "CZ"
},
]